package com.cxdr.awsips.distribute.rule;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;
import org.apache.log4j.Logger;

import com.cxdr.awsips.common.logger.LogFactory;

/**
 * 时间分发策略
 * 
 * @author pugang
 * 
 */
public class StationRule {
	private static Logger logger = LogFactory.makeNewLogger(StationRule.class);
	private String id;
	private String filter_type;
	public String station_id;
	public static final String INCLUDE_TYPE = "include";
	public static final String OUT_TYPE = "out";

	public StationRule() {

	}

	public StationRule(String filter, String station_id) {
		setFilter_type(filter);
		setStation_id(station_id);
	}

	public StationRule(String id, String filter, String station_id) {
		setId(id);
		setFilter_type(filter);
		setStation_id(station_id);
	}

	public boolean accept(String station_id) {
		boolean accept = false;
		station_id = station_id == null ?"" :station_id;
		if (INCLUDE_TYPE.equals(filter_type)) {
			accept = station_id.equals(getStation_id());
		} else if (OUT_TYPE.equals(filter_type)) {
			accept = !station_id.equals(getStation_id());
		}
		return accept;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getFilter_type() {
		return filter_type;
	}

	public void setFilter_type(String filter_type) {
		if (!INCLUDE_TYPE.equals(filter_type) && !OUT_TYPE.equals(filter_type)) {
			throw new RuntimeException("filter_type should be " + INCLUDE_TYPE
					+ " or " + OUT_TYPE + " !");
		}
		this.filter_type = filter_type;
	}

	public static void main(String[] args) throws ParseException {
	}

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		StationRule.logger = logger;
	}

	public String getStation_id() {
		return station_id;
	}

	public void setStation_id(String station_id) {
		this.station_id = station_id;
	}

	public static String getIncludeType() {
		return INCLUDE_TYPE;
	}

	public static String getOutType() {
		return OUT_TYPE;
	}
	
	public String desc(){
		return "filter_type："+filter_type+" station_id："+station_id;
	}

}
